﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<UI.Areas.Admin.Models.ProductModel>" %>
<%@ Import Namespace="UI.Helper" %>
<%= Utils.IncludeJS(this.Html, "~/Scripts/jquery.validate.min.js")%>
<%= Utils.IncludeJS(this.Html, "~/Scripts/Admin/ckeditor/ckeditor.js")%>
<%= Html.IncludeJS("~/Scripts/Admin/ckeditor/adapters/jquery.js") %>
<!-- start id-form -->
<table border="0" cellpadding="0" cellspacing="0" id="id-form">
    <tr>
        <th valign="top">
            Tên:
        </th>
        <td>
            <%: Html.TextBoxFor(c => c.Name, new { @class = "inp-form", id = "Name" })%>
        </td>
        <td>
        </td>
    </tr>
    <tr>
        <th valign="top">
            Danh mục:
        </th>
        <td>
            <% if (Model.CategoryId > 0)
               {%>
            <%: Html.DropDownListFor(c => c.CategoryId, new SelectList(Model.Categories, "Id", "Name", Model.CategoryId))%>
            <%} %>
            <% else
               {%>
            <%: Html.DropDownListFor(c => c.CategoryId, new SelectList(Model.Categories, "Id", "Name"))%>
            <%} %>
        </td>
        <td>
        </td>
    </tr>
    <tr>
        <th valign="top">
            Mô tả:
        </th>
        <td>
            <%: Html.TextAreaFor(c => c.Description, new { id = "Description" })%>
        </td>
        <td>
        </td>
    </tr>
    <tr>
        <th valign="top">
            Hình:
        </th>
        <td>
            <%: Html.TextBoxFor(c => c.Url, new { @class = "inp-form", id = "Url" })%>
        </td>
        <td>
        </td>
    </tr>
    <tr>
        <th>
            &nbsp;
        </th>
        <td valign="top">
            <input type="submit" value="" class="form-submit" />
            <% if (Model.ProductId > 0)
               {%>
            <%: Html.HiddenFor(o => o.ProductId) %>
            <%
               }%>
        </td>
        <td>
        </td>
    </tr>
</table>
<!-- end id-form  -->
<script type="text/javascript">
    $(document).ready(function () {
        $("#infoForm").validate({
            rules:
            {
                Name: { required: true },
                Description: { required: true },
                Url: { required: true }
            },
            messages:
            {
                Name: { required: 'Hãy nhập tên sản phẩm.' },
                Description: { required: 'Hãy nhập mô tả sản phẩm.' },
                Url: { required: 'Hãy nhập đường dẫn hình.' }
            },
            errorElement: "div"
        });

        //CKEditor
        $('#Description').ckeditor();
        var editor = CKEDITOR.instances.Description;

        editor.on("instanceReady", function () {
            //set keyup event
            this.document.on("keyup", ChangeDescription);

            //and paste event
            this.document.on("paste", ChangeDescription);
        })

        function ChangeDescription() {
            var data = editor.getData();
            $("#Description").attr("value", data);
            //CKEDITOR.instances.editor1.updateElement();
        }
    });
</script>